<?php echo $this->render('link/header.phtml') ?>
<?php $gridId=uniqid(); ?>
//常用变量初始化
var menuAddUrl=baseUrl+'/link/serverlink/type/addarticlereference';
var module="link.article.add";
var gridTitle="引用软文";

Ext.form.Field.prototype.msgTarget = 'side';
          
site_combo_store.load();
var site_combo=new Ext.form.ComboBox({
										width:80,
										 fieldLabel:'站点类型',
										 store:site_combo_store,										
        								displayField:'site_type',
        								valueField :'site_id',
										hiddenName:"site_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true
										 });
  
//避免自动定义combo内容，重新定义一个store.                                        
var client_combo_store_link_add=new Ext.data.JsonStore({
																	  url:baseUrl+'/link/serverclient/',
																	  totalProperty: 'total',
																	  root:'results',
																	  fields:['client_id','client_company','client_host']
																	});                                         
var client_combo=new Ext.form.ComboBox({
										width:280,
										 fieldLabel:'选择客户',
										 store:client_combo_store_link_add,										
        								displayField:'client_host',
        								valueField :'client_id',
										hiddenName:"client_id",
        								typeAhead:false,
        								triggerAction:'all',
                                        queryParam:'client_host',                                                                               
                                        //hideTrigger: true, //隐藏下拉箭头   
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
        								emptyText:'请选择...',                                       
        								selectOnFocus:true,
                                        resizable:true, 
                                        listeners:{
                                        	select:function(){
                                        	keyword_combo_store.load({params:{start:0,limit:30,client_id:this.value}});	
                                        	}
                                        }
										 });         
                                                                                
var link_add=new Ext.FormPanel({
	frame:true,
    title:gridTitle,
    labelWidth:80,
    //width:800,
    autoWidht:true,
    autoHeight:true,
    renderTo:'grid_<?=$gridId?>',
    bodyStyle:'padding:0 0 0 0;',    
    items:[
    		{
            xtype:'textfield',
            fieldLabel:'标题',
            width:600,
            name:'article_title',
            value:'<?=$this->article_title?>',
            allowBlank:false
        	},{
            xtype:'hidden',
            value:'1',
            name:'linktype_id'
            },{
            xtype:'hidden',
            value:'<?=$this->id?>',
            name:'article_id'
            },{
            xtype:'htmleditor',
            width:600,
            height:250,
            name:'article_content',
            value:'<?=$this->article_content?>',
            fieldLabel:'软文正文',
            allowBlank:false
            },{ layout:'column',
            border:false,
            items:[{
            columnWidth:.7,
                layout: 'form',
                border:false,
                items: [ {
                    xtype:'textfield',
                    fieldLabel: 'Inbound Link',
                    name: 'link_address',
                    anchor:'95%',
                    vtype:'url',
                    allowBlank:false
                }]
            },{
            columnWidth:.28,
            layout:'form',
            border:false,
            items:[
            site_combo
            ]
            }]
           },client_combo,{
           	id:'itemselector'+ExtId,
            xtype:"itemselector",
            name:"link_keyword_id",
            fieldLabel:"选择关键词",
            dataFields:["keyword_name", "keyword_id","keyword_link"],
            toData:[],
            msWidth:400,
            toWidth:400,
            delimiter:",",
            msHeight:200,
            typeAhead:true,
            valueField:"keyword_id",
            displayField:"keyword_name",
            qtipField:'keyword_link',
            imagePath:baseUrl+"/public/images/icons/",
            toLegend:"已选择",
            fromLegend:"关键词列表(可拖拉)",
            fromStore:keyword_combo_store, 
            fromTBar:[{
            xtype:'textfield',
            autoWidth:true,
            enableKeyEvents:true,
            width:250,
            value:'搜索字符串',
            listeners:{
            keyup:function(){            	
            	var value=this.getValue();
                var _tempStore=Ext.getCmp("itemselector"+ExtId).fromStore;
                _tempStore.filter('keyword_name',eval("/"+value+"/ig"));                
            	},
            focus:function(){            	
            	var value=this.getValue();
                if(value=='搜索字符串'){
                this.setValue("");
                }
            }
            }
            },{xtype:'tbfill'},{
            xtype:'textfield',
            width:80,
            enableKeyEvents:true,
            value:'匹配首字母',
            listeners:{
            keyup:function(){
            var value=this.getValue();
            var _tempStore=Ext.getCmp("itemselector"+ExtId).fromStore;
            _tempStore.filter('keyword_name',value);                
            },
            focus:function(){
            var value=this.getValue();
            if(value==='匹配首字母'){
            this.setValue("");
            }
            }
            }
            }],           
            toTBar:[{
                text:"清除",
                handler:function(){
                    var i=link_add.getForm().findField("itemselector"+ExtId);
                    i.reset.call(i);
                }
            }]
        }		  	
    ],
    buttons:[
    {
    id:'submit',
    text:'提交',
    type:'submit',
    iconCls:'icn-control',
    handler:function(){
    if(link_add.getForm().isValid()){
    link_add.getForm().submit({
    waitTitle:'提示',
    waitMsg:'请稍等',
    url:menuAddUrl,
    success:function(form,action){
    	var _message=Ext.util.JSON.decode(action.response.responseText);
		Ext.MessageBox.alert('提示',_message.msg,function(){
        Ext.getCmp('content').getActiveTab().getUpdater().refresh();
        });
    },
    failure:function(form,action){
    	var _message=Ext.util.JSON.decode(action.response.responseText);
        Ext.MessageBox.alert('提示',_message.msg);
    }
    });
    }   
    }},{
    text:'退出',
    handler:function(){
   	Ext.getCmp('content').remove(Ext.getCmp('content').getActiveTab());
    }
    }
    ]
});

});
</script>
<body style="width:98%;height:100%">
<div id='grid_<?=$gridId?>'></div>
</body>
</html>
